package com.jvm;

import sun.misc.Launcher;

import java.net.URL;

public class TestJDKClassLoader {

    public static void main(String[] args) {
         System.out.println(String.class.getClassLoader()); //引导类加载器,底层使用C++实现,所以是null
         System.out.println(com.sun.crypto.provider.DESKeyFactory.class.getClassLoader().getClass().getName()); //扩展类加载器
         System.out.println(TestJDKClassLoader.class.getClassLoader().getClass().getName());//应用程序加载器

         System.out.println();
         ClassLoader appClassLoader = ClassLoader.getSystemClassLoader(); //他们不是继承关系,而是相互建立关系
         ClassLoader extClassloader = appClassLoader.getParent();
         ClassLoader bootstrapLoader = extClassloader.getParent();
         System.out.println("the bootstrapLoader : " + bootstrapLoader);
         System.out.println("the extClassloader : " + extClassloader);
         System.out.println("the appClassLoader : " + appClassLoader);

         System.out.println();
         System.out.println("bootstrapLoader加载以下文件：");
         URL[] urls = Launcher.getBootstrapClassPath().getURLs();
         for (int i = 0; i < urls.length; i++) {
             System.out.println(urls[i]);
             }

         System.out.println();
         System.out.println("extClassloader加载以下文件：");
         System.out.println(System.getProperty("java.ext.dirs"));

         System.out.println();
         System.out.println("appClassLoader加载以下文件：");
         System.out.println(System.getProperty("java.class.path"));

         }
 }


